package asteroids.entity;

import asteroids.engine.Utils;
import asteroids.engine.Utils.PolarCoordinate;

/**
 * Icing is used to add non-game-altering effects to GameObjects
 * 
 * @author whitecd1
 */
public class Icing extends GameObject
{
    private int lifespan;
    private boolean eternal = false; // set this to true and the Icing will
                                     // never expire

    public Icing(double x, double y, int lifespan, PolarCoordinate[] shape, ObjectType type)
    {
        super(x, y, shape, type);
        this.lifespan = lifespan;
    }

    public Icing(double x, double y, int lifespan, PolarCoordinate[] shape)
    {
        this(x, y, lifespan, shape, GameObject.ObjectType.ICING);
    }

    public Icing(double x, double y, int lifespan)
    {
        this(x, y, lifespan, Utils.POINT_SHAPE, GameObject.ObjectType.ICING);
    }

    public Icing(double x, double y, boolean eternal, PolarCoordinate[] shape)
    {
        this(x, y, 0, shape);
        this.eternal = true;
    }

    public Icing(double x, double y, boolean eternal)
    {
        this(x, y, 0);
        this.eternal = eternal;
    }

    public void setLifespan(int life)
    {
        lifespan = life;
    }

    public void setEternality(boolean b)
    {
        eternal = b;
        if( eternal )
        {
            alive = true;
        }
    }

    public void update()
    {
        if( lifespan <= 0 && !eternal )
        {
            alive = false;
        }
        lifespan--;
        super.update();
    }

    public String toString()
    {
        return "Icing@" + x_position + "," + y_position + "|" + x_speed + "," + y_speed;
    }
}
